/* Copyright (c) 2011 by Mani Brundha Kattamuri, Haritha Subramanyam
 *
 * Project Info:  http://code.google.com/p/andriod-travelapp-csc780/wiki/Design
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
 * License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
 * USA.
 */
package com.example.TravelApp.search.quick;

import kankan.wheel.widget.WheelView;
import kankan.wheel.widget.adapters.ArrayWheelAdapter;
import android.widget.TextView;
import com.example.TravelApp.R;
import com.example.TravelApp.constants.AdvancedLocationInfo;
import com.example.TravelApp.search.common.helper.GeoCoderForLocationHelper;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.content.Intent;
import android.graphics.Typeface;

/**
 * This activity is displayed for user to do quick search. The layout is
 * described in file <code>res/layout/choices_layout.xml</code>. This activity
 * is used to collect the user preferences of interest and place.
 * 
 * @author Haritha Subramanyam, Mani Brundha
 * 
 */
public class QuickSearchActivity extends Activity {

	WheelView intrests, time, place;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.choices_layout);

		TextView txt = (TextView) findViewById(R.id.welcomeText);
		Typeface font = Typeface.createFromAsset(getAssets(),
				"Chantelli_Antiqua.ttf");
		txt.setTypeface(font);

		/*
		 * Create adapters for place and interest and set these adapters to the
		 * spinners also sets the number of visible items and the current
		 * visible item
		 */

		place = (WheelView) findViewById(R.id.places);
		ArrayWheelAdapter<String> placeAdapter = new ArrayWheelAdapter<String>(
				this, AdvancedLocationInfo.getPlacesArray());
		place.setViewAdapter(placeAdapter);
		place.setVisibleItems(3);
		place.setCurrentItem(1);

		intrests = (WheelView) findViewById(R.id.intrests);
		ArrayWheelAdapter<String> intrestAdapter = new ArrayWheelAdapter<String>(
				this, AdvancedLocationInfo.getLVItems());
		intrests.setViewAdapter(intrestAdapter);
		intrests.setVisibleItems(3);
		intrests.setCurrentItem(1);

	}

	/**
	 * Called whenever TabOptionDetailsMapActivity terminates.
	 */
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);

		if (resultCode == RESULT_OK) {
			// int calls = data.getExtras().getInt("CALLS");
			// resultField.setText("Calls to YellowActivity: " + calls);
		}
	}

	/**
	 * Invoked whenever the button is clicked in the QuickSearchActivity.
	 * Triggers the invocation of TabOptionDetailsMapActivity and sends in the
	 * users selected preferences as intent.
	 */
	public void onClick(View v) {
		// resultField.setText("");
		String selectedPlace = GeoCoderForLocationHelper
				.getLocationCoordinates(AdvancedLocationInfo.getPlacesArray()[place
						.getCurrentItem()]);
		String selectedInterest = AdvancedLocationInfo.getLVItems()[intrests
				.getCurrentItem()];
		Intent intent = new Intent(this, TabOptionDetailsMapActivity.class)
				.putExtra("Place", selectedPlace).putExtra("Intrest",
						selectedInterest);
		startActivityForResult(intent, 0);
	}

}